package com.oa.modules.approvalsec1.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.oa.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.juli.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.oa.modules.approvalsec1.entity.ApprovalTotalEntity;
import com.oa.modules.approvalsec1.service.ApprovalTotalService;
import com.oa.common.utils.PageUtils;
import com.oa.common.utils.R;



/**
 * 审批数据统计
 *
 * @author jimboo
 * @email jimboo7339@163.com
 * @date 2022-08-11 16:04:32
 */
@RestController
@RequestMapping("approvaltotal")
@Api(tags = "审批数据统计相关接口")
public class ApprovalTotalController extends AbstractController {
    private static final Logger log = LoggerFactory.getLogger(ApprovalTotalController.class);
    @Autowired
    private ApprovalTotalService approvalTotalService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = approvalTotalService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "信息")
    public R info(@PathVariable("id") Integer id){
		ApprovalTotalEntity approvalTotal = approvalTotalService.getById(id);

        return R.ok().put("approvalTotal", approvalTotal);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public R save(@RequestBody ApprovalTotalEntity approvalTotal){
		approvalTotalService.save(approvalTotal);

        return R.ok();
    }


    @PostMapping("/saveWaitPass")
    @ApiOperation(value = "保存待预审数据(dataType=1)")
    public R saveWaitPass(@RequestBody List<ApprovalTotalEntity> list){
        log.info("数据=====>>>>>"+list);
        //批量插入待预审数据
        //approvalTotalService.batchSave(list);
        for (ApprovalTotalEntity approvalTotalEntity:list) {
            //判断是否是空数据
            if(!"".equals(approvalTotalEntity.getReceiveNumber()) && approvalTotalEntity.getReceiveNumber()!=null){
                //查询是否已存在数据
                ApprovalTotalEntity data =  approvalTotalService.select(approvalTotalEntity);
                if (data==null){
                    //不存在
                    //插入预审超时数据
                    approvalTotalService.singleSave(approvalTotalEntity);

                }
            }

        }
        return R.ok();
    }

    @PostMapping("/savePass")
    @ApiOperation(value = "保存预审通过数据(dataType=2)")
    public R savePass(@RequestBody List<ApprovalTotalEntity> list){
        log.info("数据=====>>>>>"+list);
        //把预审通过的数据中的曾经出现过的待预审数据 处理掉  status设置为1
        //approvalTotalService.batchUpdate(list);
        //批量插入预审通过数据
        //approvalTotalService.batchSave(list);

        for (ApprovalTotalEntity approvalTotalEntity:list) {
            //判断是否是空数据
            if(!"".equals(approvalTotalEntity.getReceiveNumber()) && approvalTotalEntity.getReceiveNumber()!=null) {
                //查询是否已存在数据
                ApprovalTotalEntity data = approvalTotalService.select(approvalTotalEntity);
                if (data == null) {
                    //不存在
                    //更新待预审表
                    approvalTotalService.singleUpdate(approvalTotalEntity);
                    //插入预审通过数据
                    approvalTotalService.singleSave(approvalTotalEntity);

                }
            }
        }

        return R.ok();
    }


    @PostMapping("/saveOverTimePass")
    @ApiOperation(value = "保存预审超时数据(dataType=3)")
    public R saveOverTimePass(@RequestBody List<ApprovalTotalEntity> list){
        log.info("数据=====>>>>>"+list);
        //把预审通过的数据中的曾经出现过的待预审数据 处理掉  status设置为1
        //approvalTotalService.batchUpdate(list);
        //批量插入预审通过数据
        //approvalTotalService.batchSave(list);
        for (ApprovalTotalEntity approvalTotalEntity:list) {
            //判断是否是空数据
            if(!"".equals(approvalTotalEntity.getReceiveNumber()) && approvalTotalEntity.getReceiveNumber()!=null) {
                //查询是否已存在数据
                ApprovalTotalEntity data = approvalTotalService.select(approvalTotalEntity);
                if (data == null) {
                    //不存在
                    //更新待预审表
                    approvalTotalService.singleUpdate(approvalTotalEntity);
                    //插入预审超时数据
                    approvalTotalService.singleSave(approvalTotalEntity);

                }
            }
        }
        return R.ok();
    }

    @PostMapping("/saveHallHandle")
    @ApiOperation(value = "保存大厅办件数据(dataType=4)")
    public R saveHallHandle(@RequestBody List<ApprovalTotalEntity> list){
        log.info("数据=====>>>>>"+list);
        //批量插入预审通过数据
        //approvalTotalService.batchSave(list);
        for (ApprovalTotalEntity approvalTotalEntity:list) {
            //判断是否是空数据
            if(!"".equals(approvalTotalEntity.getReceiveNumber()) && approvalTotalEntity.getReceiveNumber()!=null) {
                //查询是否已存在数据
                ApprovalTotalEntity data = approvalTotalService.select(approvalTotalEntity);
                if (data == null) {
                    //不存在
                    //插入预审超时数据
                    approvalTotalService.singleSave(approvalTotalEntity);

                }
            }
        }
        return R.ok();
    }


    @PostMapping("/saveSpecialItem")
    @ApiOperation(value = "保存投资专项数据(dataType=5)")
    public R saveSpecialItem(@RequestBody List<ApprovalTotalEntity> list){
        log.info("数据=====>>>>>"+list);

        //批量插入预审通过数据
        //approvalTotalService.batchSave(list);
        for (ApprovalTotalEntity approvalTotalEntity:list) {
            //判断是否是空数据
            if(!"".equals(approvalTotalEntity.getReceiveNumber()) && approvalTotalEntity.getReceiveNumber()!=null) {
                //查询是否已存在数据
                ApprovalTotalEntity data = approvalTotalService.select(approvalTotalEntity);
                if (data == null) {
                    //不存在
                    //插入预审超时数据
                    approvalTotalService.singleSave(approvalTotalEntity);

                }
            }
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public R update(@RequestBody ApprovalTotalEntity approvalTotal){
		approvalTotalService.updateById(approvalTotal);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public R delete(@RequestBody Integer[] ids){
		approvalTotalService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
